package main

import (
	"github.com/didip/tollbooth"
	"github.com/gin-gonic/gin"
	"net/http"
	"nodeseller/limit"
	"nodeseller/middleware"
	"nodeseller/router/billrouter"
	"nodeseller/router/productrouter"
	"nodeseller/router/storerouter"
	"nodeseller/router/topuprouter"
	"nodeseller/router/userrouter"
)

func main()  {
	app := gin.Default()
	app.Static("/static","./public/static")
	app.LoadHTMLGlob("./public/html/*.html")

	app.GET("/", func(context *gin.Context) {
		context.HTML(http.StatusOK,"index.html",nil)
	})
	userlimit := tollbooth.NewLimiter(5000,nil)
	userlimit.SetMessage("服务器繁忙，请稍后再试....")
	user := app.Group("/user",limit.UserLimitHandler(userlimit))
	{
		user.POST("/register", userrouter.UserRegister)
		user.POST("/login", userrouter.UserLogin)
		user.POST("/getuserinfo",middleware.CheckUserInfo, userrouter.UserGetInfo)
	}
	product := app.Group("/product")
	{
		product.POST("/create",middleware.CheckUserInfo, productrouter.CreateOrder)
		product.POST("/deleteproduct",middleware.CheckUserInfo, productrouter.DeleteOrder)
		product.POST("/finddoing",middleware.CheckUserInfo, productrouter.FindAllDoing)
		product.POST("/findfined",middleware.CheckUserInfo, productrouter.FindAllFined)
		product.POST("/finddelete",middleware.CheckUserInfo, productrouter.FindAllDelete)
	}
	store := app.Group("/store")
	{
		store.POST("/create",middleware.CheckUserInfo, storerouter.CreateOrder)
		store.POST("/findall",middleware.CheckUserInfo, storerouter.FinSelfStoreAll)
	}
	bill := app.Group("/bill")
	{
		bill.POST("/findall",middleware.CheckUserInfo, billrouter.FindAllBill)
	}
	topup := app.Group("/topup")
	{
		topup.POST("/create",middleware.CheckUserInfo, topuprouter.CreateTopUp)
		topup.POST("/findallwaitcancel",middleware.CheckUserInfo,topuprouter.FindAllWaitCancel)
		topup.POST("/findallfinedcancel",middleware.CheckUserInfo,topuprouter.FindAllFinedCancel)
	}
	app.Run(":8080")
}
